
--EXEC SP_CREATE_UPDATE_NONVALUE_INVENTORY_LOT 13358, 435, '04/09/2009', '1;2;3', 'MANULLAY INSERT', 'Admin'

ALTER PROC SP_CREATE_UPDATE_NONVALUE_SCRAP_LOT
(
	@LOT_ID		INT,
	@QTY_IN		INT,
	@DATE_IN    DATETIME,
	@WAFERIDS	VARCHAR(300),
	@COMMENTS 	VARCHAR(500),
	@USER_NAME	VARCHAR(50)
)
AS
BEGIN
	
	DECLARE @PRV_SCRAPED_WAFERIDS 		VARCHAR(300)
	DECLARE @PRV_SCRAPED_WAFERIDS_AS_COMMA	 VARCHAR(300)
    DECLARE @SCRAPPED_WAFERIDS_AS_COMMA	 VARCHAR(300)
	DECLARE @PRV_SCRAPED_WAFER_IDS_TABLE 	TABLE ( WAFER_ID INT )
	DECLARE	@SCRAPED_WAFER_IDS_TABLE    TABLE ( WAFER_ID INT )
	DECLARE @WAFER_IDS_TABLE 		TABLE ( WAFER_ID INT )
	DECLARE @CONCAT_WAFERS_INTO_STRING 	VARCHAR(300)

	IF @QTY_IN > 0  
	BEGIN
			INSERT INTO SCRAPPED_LOTS_HISTORY SELECT * FROM SCRAPPED_LOTS WHERE LOT_ID = @LOT_ID AND SL_SCRAPPED_DATE = CONVERT( VARCHAR, @DATE_IN, 101 ) AND IS_NONVALUE_INVENTORY = 0
			
			UPDATE SCRAPPED_LOTS SET SL_UPDATED_BY = @USER_NAME, IS_NONVALUE_INVENTORY = 1--,SL_COMMENTS = SL_COMMENTS + @COMMENTS					 
				WHERE LOT_ID = @LOT_ID AND SL_SCRAPPED_DATE = CONVERT( VARCHAR, @DATE_IN, 101 )
	END
END